Hi everyone,
I think my weekend plans have changed since watching the 'live trading' webinar on Thursday :-) So I am getting on with my coding and I have a little bit of experience working in Python. I am aiming to compute the continuously compounded returns of a range of assets (the ETFs under the initialisation function). However, I am completely stuck:
# Put any initialization logic here. The context object will be passed to
# the other methods in your algorithm.
# Imports
import datetime
import numpy as np
import pandas as pd
def initialize(context):
# Equities
context.IVV = sid(21513) # Benchmark: S&P 500, Core Large-cap US
# context.IWM = sid(21519) # Benchmark: Russell 2000, Small-cap US
# context.EEM = sid(24705) # Benchmark: MSCI Emerging Markets, Large-cap EM
# context.EWJ = sid(14520) # Benchmark: MSCI Japan, Large-cap JP
# context.IEV = sid(21769) # Benchmark: S&P Europe 350, Large-cap European
# context.EWG = sid(14518) # Benchmark: MSCI Germany, Large-cap Germany
# context.EWU = sid(14529) # Benchmark: MSCI UK, Large-cap UK
# Fixed Income
# context.LQD = sid(23881) # Benchmark: iBoxx IG Corporates, US
# context.HYG = sid(33655) # Benchmark: iBoxx HY Corporates, US
# context.IEF = sid(23870) # Benchmark: 7-10yr Treasuries, US
# context.IEI = sid(33151) # Benchmark: 3-7yr Treasuries, US
context.SHY = sid(23911) # Benchmark: 1-3yr Treasuries, US
context.SHV = sid(33154) # Benchmark: Barclays U.S. Short Treasury Bond , US
# context.EMB = sid(35323) # Benchmark: JPM EMBI Global Core Index, Global EM FI
# Commodities
# context.IAU = sid(26981) # Benchmark: London Gold PM Fix
# Volatility
context.VXX = sid(38054) # S&P 500 VIX Short-Term Futures
# Maximum and Minimum amounts we want the algorithm to go long
context.max_notional = 1000000.1
context.min_notional = -1000000.0
# Computing logarithmic returns of assets
def CC_Returns(datapanel):
Basically, I understand that I can use the history function to pull the historic data for the past x days, but surely there is an easier way then typing out
2d_close = history(2, "1d", "price")
....
100d_close = history(100, "1d", "price")
and from then on I could calculate:
log(2d_close / 3d_close), ..... log(99d_close / 100d_close)
and store these variables in a list.
How can this actually be translated into useful code? Thank you all for your help!