Design a site like this with
Get started

Complete Backtest Using Ingested Zipline Data

Import necessary functions in Python Set target weights for each ticker Set rebalance rules, i.e. monthly Set benchmark, i.e. SPY Set start and end dates – should match trade dates in zipline ingested files Create benchmark file Make sure benchmark dates align with trade dates Run backtest analysis If there are modules to import –Continue reading “Complete Backtest Using Ingested Zipline Data”

Ingesting A Zipline Data Bundle

Update Users/NAME/.zipline/ (needs to be updated every time you are ingesting a bundle) To locate you will need to unhide files, Command + Shift + Dot (.) on mac Update the start_session & end_session to match the trading start date and end date Update bundle name and ensure file location is correct Update (oneContinue reading “Ingesting A Zipline Data Bundle”

Creating A Zipline Data Bundle

Get daily OHLCV stock data using Python via YahooFinance,, etc and save as a CSV file Import necessary python modules Set start & end dates manually Run pdr.DataReader spy = pdr.DataReader(‘SPY’, ‘yahoo’, start_date, end_date) Save data to CSV spy.to_csv(‘/Users/bars_adj/spy.csv’) Index dates to Zipline Trading calendar Create trading_days tag in python Start & end datesContinue reading “Creating A Zipline Data Bundle”

Exchange Traded Funds (ETFs)

Pros Passive, low cost index trackers – i.e. SPY Such ETFs track major country, sector, and bond indexes Cash instruments make things simple, pay for what you want to buy and have a linear payoff Trading futures, options, swaps, forwards and other derivatives creates complications Cons Anyone can create an ETF and charge whatever theyContinue reading “Exchange Traded Funds (ETFs)”

Time Series Analytics

Semi-log graph of equity curve Exposure over time Half year rolling return, annualized Useful to see what annualized would look like in a shorter time firm AnnualizedReturn = (EndValue/StartValue)^YearDays/ActualDays-1 Python: def ann_ret(ts): return np.power((ts[-1]/ts[0]), (year_length/len(ts)))-1 Maximum Drawdown Python: def dd(ts): return np.min(ts/np.maximum.accumulate(ts)) – 1 Recalculate time series vs benchmarks with same starting point Python: defContinue reading “Time Series Analytics”

Imports & Functions Required For Backtests

Zipline Functions from zipline import run_algorithm #needed every time we run a backtest from zipline.api import order_target_percent #ability to place orders in terms of target percent from zipline.api import order_target #ability to place orders in terms of shares from zipline.api import symbol #ability to look at stocks based on ticker from zipline.api import record fromContinue reading “Imports & Functions Required For Backtests”

Setting Up A Backtest

Data Sources Norgate Data for stocks CSI Data for futures Quandl is a FREE data source Backtesting Engine Zipline by Quantopian Major downside of zipline is that is only aware of a single world currency. Back testing securities with multiple currency denominations will not work. Works with both equities and futures Should have its ownContinue reading “Setting Up A Backtest”

Correlation Graph in Python

Must use either log returns or percentage returns Standard approach is to use log returns The following python code will generate a correlation chart of the rolling 50 day window of the returns, showing the last 200 data points: df[‘SP500’].rolling(50).corr(df[‘NDX’])[-200:].plot() The slice function is used to grab specific data points from a data frame [start:stop:step]Continue reading “Correlation Graph in Python”