This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
from copy import copy | |
def ishead(): | |
result=random.uniform(0,1) | |
if result>=0.5: | |
return 1 | |
else: | |
return 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from syslogdiag.ourlogging import logger | |
from math import copysign | |
def contracts_trade(total_trades, pos_priced, pos_forward, rolling=False): | |
""" | |
Given actual contracts decide what to trade | |
Note at this stage contracts are identified in as PRICE, FORWARD | |
Any rogue contracts not in that space would have been signalled / weeded out by now |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import matplotlib | |
#matplotlib.use("TkAgg") | |
import matplotlib.pyplot as plt | |
from scipy.optimize import minimize | |
import numpy as np | |
### Following is the optimisation code: | |
### First the main function. | |
def optimise_with_sigma(sigma, mean_list): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib | |
matplotlib.use("TkAgg") | |
import matplotlib.pyplot as plt | |
from scipy.optimize import minimize | |
import numpy as np | |
import scipy.stats as stats | |
from scipy.stats import norm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
The starter system has the following features: | |
- single market | |
- binary forecast from simple MAV | |
- exit from trailing stop loss | |
- fixed positions once in trade | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Following code is boilerplate for optimising | |
import matplotlib | |
matplotlib.use("TkAgg") | |
import pandas as pd | |
from scipy.optimize import minimize | |
import numpy as np | |
from scipy.stats import norm | |
from collections import namedtuple | |
def optimise_for_corr_matrix(corr_matrix): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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: |