Cash and Cash Equivalents

(Cash + immediately liquid instruments)

An algorithm that trades stocks with the highest values of cash and cash equivalents weekly.

Starting capital: $10,000
Max leverage: 1
Jan 2, 2006 - Sep 1, 2020

Returns: -51.42%
Drawdown: -77.4%
Benchmark (S&P 500): 276.95%
import quantopian.algorithm as algo
from quantopian.pipeline import Pipeline
from quantopian.pipeline.filters import Q3000US
from quantopian.pipeline.data.morningstar import Fundamentals as ms
import quantopian.optimize as opt

import numpy as np
import pandas as pd


def initialize(context):
    context.FINE_FILTER = 5
    context.stock_weights = pd.Series()
    algo.attach_pipeline(make_pipeline(context), 'pipeline')

    schedule_function(
        stocks_weights,
        date_rules.week_start(),
        time_rules.market_open()
    )

    schedule_function(
        trade,
        date_rules.week_start(),
        time_rules.market_open()
    )


def make_pipeline(context):
    univ = Q3000US()
    factor = ms.cash_and_cash_equivalents.latest.rank(mask=univ, ascending=False)
    top = factor.top(context.FINE_FILTER)
    pipe = Pipeline(
        columns={'top': top}, screen=univ)
    return pipe


def stocks_weights(context, data):
    df = algo.pipeline_output('pipeline')
    rule = 'top'
    stocks_to_hold = df.query(rule).index
    stock_weight = 1.0 / context.FINE_FILTER
    context.stocks_weights = pd.Series(index=stocks_to_hold, data=stock_weight)


def trade(context, data):
    target_weights = opt.TargetWeights(context.stocks_weights)

    constraints = []
    constraints.append(opt.MaxGrossExposure(1.0))

    order_optimal_portfolio(
        objective=target_weights,
        constraints=constraints
    )

Total Assets

Tangible and intangible value.

An algorithm that trades stocks with the highest values of total assets weekly.

Starting capital: $10,000
Max leverage: 1
Jan 2, 2006 - Sep 1, 2020

Returns: -51.27%
Drawdown: -83.72%
Benchmark (S&P 500): 276.95%
factor = ms.total_assets.latest.rank(mask=univ, ascending=False)

Total Equity

(Assets - liabilities)

An algorithm that trades stocks with the highest values of total equity weekly.

Starting capital: $10,000
Max leverage: 1
Jan 2, 2006 - Sep 1, 2020

Returns: 185.64%
Drawdown: -78.54%
Benchmark (S&P 500): 276.95%
factor = ms.total_equity.latest.rank(mask=univ, ascending=False)

Total Debt

Current and long-term debts owed.

An algorithm that trades stocks with the lowest debt weekly.

Starting capital: $10,000
Max leverage: 1
Jan 2, 2006 - Sep 1, 2020

Returns: 52.21%
Drawdown: -53.81%
Benchmark (S&P 500): 276.95%
def make_pipeline(context):
  univ = Q3000US()
  factor = ms.total_debt.latest.rank(mask=univ, ascending=True)
  bottom = factor.bottom(context.FINE_FILTER)
  pipe = Pipeline(
      columns={'bottom': bottom}, screen=univ)
  return pipe

def stocks_weights(context, data):
df = algo.pipeline_output('pipeline')
rule = 'bottom'

An algorithm that trades stocks with the highest debt weekly.

Starting capital: $10,000
Max leverage: 1
Jan 2, 2006 - Sep 1, 2020

Returns: -21.78%
Drawdown: -75.52%
Benchmark (S&P 500): 276.95%
def make_pipeline(context):
    univ = Q3000US()
    factor = ms.total_debt.latest.rank(mask=univ, ascending=False)
    top = factor.top(context.FINE_FILTER)
    pipe = Pipeline(
        columns={'top': top}, screen=univ)
    return pipe
Terms:
1. Cash and Cash Equivalents Investopedia
2. Asset Investopedia
3. Equity Investopedia
4. Net Debt Investopedia


Statements on this website are for informational purposes only and do not constitute a recommendation or advice by the website owner to transact any security or market instrument. All trading activity involves known and unknown risk. Historical data presented is not always indicative of future performance.

Social

X
Github

Contact

Email