Exemple #1
0
    def testInstantiate(self):
        account = Account(name='MyAcc', contacts=None, gc_contacts=None)

        self.assertEquals('MyAcc', account.name)
        self.assertTrue(account.gc_contacts is None)
        self.assertTrue(account.contacts is None)
Exemple #2
0
 def add_account(self, account_name):
     self._accounts[account_name] = Account(account_name, Contacts(),
                                            GC_Contacts())
     self._metacontact_manager.add_account(account_name)
def _load_ethereum_account() -> Account:
    with open(settings.PRIVATE_KEY_PATH) as keyfile:
        private_key = w3.eth.account.decrypt(keyfile.read(),
                                             settings.PRIVATE_KEY_PASSWORD)
        acc = w3.eth.account.from_key(private_key)
        return Account(address=acc.address, private_key=private_key)
from tools.binance import BinancePublic
from common.assets import assets
from common.account import Account
from backtesting.broker import Binance
from strategy.random_signal_strategy import FixedDatesTransactionsStrategy
from data.data_provider import LiveDataProvider
from risk.risk_management import BaseRiskManager
from common.event.event_handler import EventHandler

binance_broker = Binance()
binance_api = BinancePublic()
sma_strategy = FixedDatesTransactionsStrategy("Random strategy")

ether = assets.Cryptocurrency("Ethereum", "ETH", "BTC")
ether_bars = binance_api.get_candlesticks("BTC",
                                          "ETH",
                                          "1m",
                                          return_as_link=True)
ether.set_bars(ether_bars)
ether.add_strategy(sma_strategy)
portfolio = Account(1, "BTC", [ether])
risk_manager = BaseRiskManager(portfolio)
portfolio.set_risk_manager(risk_manager)
data_provider = LiveDataProvider({'ETH': ether}, sleep_time=10)
event_handler = EventHandler(portfolio, binance_broker, {'ETH': ether},
                             data_provider)
# Oracle stocks
oracle = assets.Stock(context, "Oracle", "ORCL", assets.USD())
oracle_bars = BarProvider('/shinywaffle/data/yahoo_finance/ORCL_1D.csv',
                          '%Y-%m-%d')
oracle.set_bars(oracle_bars)

# IBM stocks
ibm = assets.Stock(context, "IBM", "IBM", assets.USD())
ibm_bars = BarProvider('/shinywaffle/data/yahoo_finance/IBM_1D.csv',
                       '%Y-%m-%d')
ibm.set_bars(ibm_bars)

trading_strategy.apply_to_asset(nvidia, oracle, ibm)

risk_manager = BaseRiskManager(context)
account = Account(context, 1000, assets.USD())
backtester = Backtester(context,
                        'daily',
                        run_from=datetime(2011, 1, 1),
                        run_to=datetime(2020, 1, 1))
workflow = BacktestWorkflow(context,
                            backtester,
                            "Simple SMA workflow sample ",
                            path="/shinywaffle/backtesting/runs",
                            runs=1,
                            sub_runs=1,
                            out_of_sample_size=0.2,
                            wfa='anchored',
                            stochastic_runs=2)

workflow.set_uncertainty_parameter_values(
Exemple #6
0
import os
from tools.alpha_vantage import AlphaVantage
from common.assets import Stock
from common.account import Account
from backtesting.broker import InteractiveBrokers
from strategy.sma_crossover import AverageCrossOver
from risk.risk_management import RiskManager
from common.event.event_handler import EventHandler
from data.data_provider import LiveDataProvider

ib = InteractiveBrokers()
alpha_vantage = AlphaVantage(os.environ['AlphaVantage_APItoken'])
sma_strategy = AverageCrossOver("SMA crossover", short=20, long=50)

# Nokia stocks
nokia = Stock("Nokia", "NOK", "USD")
nokia_bars = alpha_vantage.query_stocks("TIME_SERIES_DAILY",
                                        "NOK",
                                        outputsize="full",
                                        return_as_link=True)
nokia.set_bars(nokia_bars)
nokia.add_strategy(sma_strategy)
portfolio = Account(1000, "USD", [nokia])
risk_manager = RiskManager(portfolio)
portfolio.set_risk_manager(risk_manager)

data_provider = LiveDataProvider({"NOK": nokia})
event_handler = EventHandler(portfolio, ib, {"NOK": nokia}, data_provider)