Back to Community
use bitcoin google search query to trade gold

use bitcoin google search query to trade gold

Clone Algorithm
23
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
import pandas
import math

    
def initialize(context):       
    #import google search query data on bitcoins
    #only have data between 10/01/2013 and 02/26/2014
    fetch_csv('http://pastebin.com/raw/HBvMxg9k',
        symbol='bitcoin',
        date_column='Week',
        date_format='%d-%m-%y',
        )
    context.GLD = symbol('gld')
    set_benchmark(context.GLD)
    context.trading_money = context.portfolio.cash
   
    
def handle_data(context, data):
  #Making sure there is query data to set 
  stock_amount = context.portfolio.positions[context.GLD].amount
  # How many shares can you buy
  trading_shares = int(context.trading_money/data.current(context.GLD, 'price'))
  if 'bitcoin' in data['bitcoin']:
      bitQuery = data['bitcoin']['bitcoin']
      record(bitQuery=bitQuery, stock_amount=stock_amount)
  # buy if there are low volume of bitcoin google Query
  if bitQuery<50 and stock_amount <=0:
      order(context.GLD, -stock_amount)
      order(context.GLD,+trading_shares)
  # sell if there are high volume of bitcoin google Query
  elif bitQuery>50 and stock_amount >= 0:
     order(context.GLD, -stock_amount)
     order(context.GLD,-trading_shares)
There was a runtime error.
1 response

Very Interesting