Skip to content

Quantitative algorithms, portfolio managers, data sources and contexts for Intuition

License

Notifications You must be signed in to change notification settings

obnauticus/insights

 
 

Repository files navigation

Insights

Build Status Coverage Status Code Health License

Plug-and-play building blocks for modern quants

Quantitative algorithms, portfolio managers data sources, contexts and middlewares for Intuition

Installation

# apt-get install r-base
# pip install intuition
# pip install insights

Or if you plan to hack on it

$ git clone https://github.com/hackliff/insights.git && cd insights
# pip install -r requirements.txt
$ export PYTHONPATH=$PYTHONPATH:$PWD

Now use in your intuition configuration something like

modules:
  manager: insights.managers.optimalfrontier.OptimalFrontier
  algorithm: insights.algorithms.gradient.StochasticGradientDescent
  data: insights.sources.live.EquitiesLiveSource

Getting started

  • Here is the Fair manager example, which allocates the same weight to all of your assets:
from intuition.zipline.portfolio import PortfolioFactory

class Fair(PortfolioFactory):
    '''
    Dispatch equals weigths for buy signals and give up everything on sell ones
    '''
    def optimize(self, date, to_buy, to_sell, parameters):
        allocations = dict()
        if to_buy:
            fraction = round(1.0 / float(len(to_buy)), 2)
            for s in to_buy:
                allocations[s] = fraction
        for s in to_sell:
            allocations[s] = - self.portfolio.positions[s].amount

        expected_return = 0
        expected_risk = 1
        return allocations, expected_return, expected_risk
  • A classic buy and hold strategy, with a plugin which stores metrics in rethinkdb:
from intuition.zipline.algorithm import TradingFactory
import insights.plugins.database as database

class BuyAndHold(TradingFactory):
    '''
    Simpliest algorithm ever, just buy every stocks at the first frame
    '''
    def initialize(self, properties):

        self.save = properties.get('save', False)
        if self.save:
            self.use(database.RethinkdbBackend(self.identity, reset=True)
                     .save_portfolio)

    def event(self, data):
        signals = {}

        if self.day == 2:
            for ticker in data:
                signals[ticker] = data[ticker].price

        return signals

About

Quantitative algorithms, portfolio managers, data sources and contexts for Intuition

Resources

License

Stars

Watchers

Forks

Packages

No packages published