18
CS349F CloudEx Review Session 2 Friday October 16th

CS349F CloudEx Review Session 2 - Stanford Universityweb.stanford.edu/class/cs349f/CS349F_CloudEx_Review... · 2020. 10. 16. · CloudEx Review Session 2 Friday October 16th. Session

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

  • CS349FCloudEx Review Session 2

    Friday October 16th

  • Session Outline● Connecting to VM (reminder from last week)● Python Client Library

    ○ Overview○ algorithm() Function Description

    ● Jupyter Notebook○ Section 1: Instantiate your cloud_ex.Trader object○ Trading Algorithm Examples

    ● Section 2: Mean reversion trading● Section 3: Momentum trading● Section 4: Pairs trading

    ○ Section 5: Backtesting

    ● C++ API Code Examples

  • Connecting to your VM(Reminder from last week)

  • Connecting to your VM to the VM● Check email for SSH Private Key and your VM’s public IP address. Download ssh

    key (e.g., c1_sshkey)

    1. Make ssh key read-only by owner.

    2. Use an ssh client to connect to your VM using the private key and IP address.

    chmod 400 c1_sshkey

    ssh -i c1_sshkey trader@

  • Python Client Library

  • OverviewAlgorithmicTrader

    Base Class

    Constructor arguments:

    1. cloud_ex.Trader object,

    2. list of symbols to subscribe to,

    3. bin_interval in ms - defaults to 500ms

    API functionality:

    - Pull and Bin Trade Market Data

    - Place Orders

    - Given the trading algorithm function:

    - Run Trading Loop

    - Backtest using historical data

    Client library provided by us

    Student Derived Subclass

    Required function to define:

    - The trading algorithm function algorithm()-(More about this in next slide)

    Algorithm developed by you

    (inherits AlgorithmicTrader base class functionality)

  • algorithm() Function Description

    Calculate buy/sell points for an equity

    The stock price is evaluated at the close of each bin_interval_ms time interval.

    Arguments:

    df - Dataframes with prices for an equity (pd.DataFrame).**kwargs - Any other needed (named) arguments for the algorithm

    Returns:

    An (action, price) pair.● action is None when no action is determined, price is also None in this case.● action is ‘Buy’, price is then the buy price.● action is ‘Sell’, price is then the sell price.

    algorithm(df, **kwargs)

  • Jupyter Notebook

  • Section 1: Instantiate your cloud_ex.Trader object

  • Trading Algorithm Examples

  • Section 2: Mean Reversion Trading

  • Section 3: Momentum Trading

  • Section 4: Pairs Trading

  • Section 5: Backtesting

  • Backtesting Trading Loop

    ● Use historical data to:○ Fit Algorithm Parameters○ Compare Algorithm Performance○ Evaluate expected Risk/Return profiles for

    algorithms

    ● Deploy Algorithms on live data

  • C++ API Code Examples

  • Steps to Build your C++ program with CloudEx to the VM● SSH into your VM, then change directory:

    ● There is a script that takes in your .cpp filename and the desired executable name, and compiles your cpp program to output an executable. Use that script to build

    your C++ program.

    ○ Example: to build tutorial.cpp in that directory:

    cd /root/CloudExchange

    ./buildcpp.sh tutorial.cpp tutorial

    ● Run the resulting executable output.

  • C++ Code Examples● You can check the tutorial.cpp for a basic introduction on the C++ API,

    which is almost identical to the Python API.

    ● We have also implemented the three algorithms we just discussed in C++. For example, for mean reversion trader:

    ./buildcpp.sh mean_reversion_trader.cpp mean_reversion_trader

    ./mean_reversion_trader --base_shares 1000 --moving_window 5 --threshold 5 --tick_length 1