Skip to content

Instantly share code, notes, and snippets.

View robcarver17's full-sized avatar

Robert Carver robcarver17

View GitHub Profile
import random
from copy import copy
def ishead():
result=random.uniform(0,1)
if result>=0.5:
return 1
else:
return 0
import matplotlib.pyplot as plt
import pandas as pd
import scipy.stats as stats
import numpy as np
from systems.provided.futures_chapter15.estimatedsystem import *
system = futures_system()
del(system.config.instruments) # so we can get results for everything
"""
Implement the handcrafting method
This is 'self contained code' which requires wrapping before using in pysystemtrade
"""
## CAVEATS:
## Uses weekly returns (resample needed first)
## Doesn't deal with missing assets
"""
Get some data to test the handcrafting method
"""
from sysdata.csv.csv_sim_futures_data import csvFuturesSimData
from syscore.handcrafting import Portfolio
import pandas as pd
data=csvFuturesSimData()
code_list = ['BOBL', 'BUND', 'US10', 'US20', 'KR3','KR10','EDOLLAR', 'CORN', 'CRUDE_W', 'GAS_US']
from sysdata.quandl.quandl_futures import quandlFuturesConfiguration, quandlFuturesContractPriceData
from sysdata.futures.contracts import listOfFuturesContracts
from sysdata.futures.instruments import futuresInstrument
from sysdata.mongodb.mongo_roll_data import mongoRollParametersData
import numpy as np
import pandas as pd
def get_roll_parameters_from_mongo(instrument_code):
from systems.provided.futures_chapter15.basesystem import *
sys = futures_system()
config = sys.config
del(config.instrument_weights) # ensures all instruments are used equally weighted
config.forecast_weights=dict(ewmac16_64=0.333, ewmac32_128=0.333, ewmac64_256=0.3333)
config.use_forecast_div_mult_estimates=True
config.use_instrument_div_mult_estimates=True
config.use_forecast_scale_estimates=False
system = futures_system(config=config)
acc = system.accounts.portfolio()
@robcarver17
robcarver17 / temp.py
Last active September 17, 2022 13:55
# Gist example of IB wrapper ...
#
# Download API from http://interactivebrokers.github.io/#
#
# Install python API code /IBJts/source/pythonclient $ python3 setup.py install
#
# Note: The test cases, and the documentation refer to a python package called IBApi,
# but the actual package is called ibapi. Go figure.
#
# Get the latest version of the gateway:
@robcarver17
robcarver17 / temp.py
Created September 13, 2017 11:22
currency quotes
# Gist example of IB wrapper ...
#
# Download API from http://interactivebrokers.github.io/#
#
# Install python API code /IBJts/source/pythonclient $ python3 setup.py install
#
# Note: The test cases, and the documentation refer to a python package called IBApi,
# but the actual package is called ibapi. Go figure.
#
# Get the latest version of the gateway:
@robcarver17
robcarver17 / temp.py
Last active January 2, 2024 06:02
Get IB historical data native python API updated for bar class
# Gist example of IB wrapper ...
#
# Download API from http://interactivebrokers.github.io/#
#
# Install python API code /IBJts/source/pythonclient $ python3 setup.py install
#
# Note: The test cases, and the documentation refer to a python package called IBApi,
# but the actual package is called ibapi. Go figure.
#
# Get the latest version of the gateway:
@robcarver17
robcarver17 / temp.py
Created July 6, 2017 08:09
ibAPIexample2.py
# Gist example of IB wrapper ...
#
# Download API from http://interactivebrokers.github.io/#
#
# Install python API code /IBJts/source/pythonclient $ python3 setup.py install
#
# Note: The test cases, and the documentation refer to a python package called IBApi,
# but the actual package is called ibapi. Go figure.
#
# Get the latest version of the gateway: