Skip to main content

turtle-trading


A Python Package containing a collection of investing tools using the Turtle Traders Original Rules. All code is based on the ideas in The Original Turtle Trading Rules.

Download using pip:

pip install turtle-trading

USAGE: First, initialize a DataFrameLoader class to pass as an argument to most turtle_trading functions as shown below.

from turtle_trading import DataFrameLoader

ticker = 'aapl'
dataframe = DataFrameLoader(ticker)

position_sizing module

""" using the position_sizing module """
from turtle_trading.position_sizing import getn, getunits

import datetime
date = datetime.date(2023, 11, 10)

getn(dataframe) # >>> 2.7421
getn(dataframe, date=date) # >>> 2.9932

getunits(dataframe=dataframe, account=1000000, n=2.7421) # >>> 20.0475
getunits(dataframe=dataframe, account=1000000, date=date) # >>> 17.9233

entries module

""" using the entries module """
from turtle_trading.entries import getentry, addunits

getentry(dataframe=dataframe, system=1) # >>> True
getentry(dataframe=dataframe, system=2) # >>> True

addunits(orig_breakout=310, orig_n=2.50) # >>> [310, 311.25, 312.5, 313.75]
addunits(orig_breakout=310, orig_n=2.50, number_of_units=6) # >>> [310, 311.25, 312.5, 313.75, 315.0, 316.25]

# DISCLAIMER: In the rules, no more than 4 more units are allowed for a single position.

stops module

""" using the stops module """
from turtle_trading.entries import addunits
from turtle_trading.stops import getstops

units = addunits(orig_breakout=28.30, orig_n=1.20) # >>> [28.3, 28.9, 29.5, 30.1]

getstops(stop_system="regular", unit_list=units, orig_n=1.20) # >>> [27.7, 27.7, 27.7, 27.7]
getstops(stop_system="whipsaw", unit_list=units, orig_n=1.20) # >>> [27.7, 28.3, 28.9, 29.5]


gapped_units = [28.3, 28.9, 29.5, 30.8]

getstops(stop_system="regular", unit_list=gapped_units, orig_n=1.20) # >>> [27.7, 27.7, 27.7, 28.4]
getstops(stop_system="whipsaw", unit_list=gapped_units, orig_n=1.20) # >>> [27.7, 28.3, 28.9, 30.2]

exits module

import datetime
from turtle_trading.exits import getexit

getexit(dataframe=dataframe, system=1, pos_direction=True) # >>> True

getexit(dataframe=dataframe, system=1, pos_direction=True, date=datetime.date(2023, 11, 10)) # >>> False

Official documentation coming soon...

For issues, look here.

Metadata

Release files for turtle-trading 3.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for turtle-trading 3.5.1
File Size Uploaded
turtle_trading-3.5.1.tar.gz 2.9 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for turtle-trading 3.5.1
File Interpreter ABI Platform
turtle_trading-3.5.1-py3-none-any.whl Python 3 none any Details

Total release size: 2.9 MB

Release files / turtle_trading-3.5.1.tar.gz

Download URL turtle_trading-3.5.1.tar.gz
Size 2.9 MB
Tags Source
SHA-256 checksum
How to use checksums
b785eade97f40fcfcc95f42f2c530be61b748a3384be251c2ad879823815e5b2
BLAKE2b-256 checksum
How to use checksums
ac59fc7a42dee97e009a4496b19990a01790d95bbc4237931ad43de66366c3a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.5

Release files / turtle_trading-3.5.1-py3-none-any.whl

Download URL turtle_trading-3.5.1-py3-none-any.whl
Size 17.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0368bf7605fa451a8e1b58c3143dee6d0507ea0f47542b4647c0de5cf83fb209
BLAKE2b-256 checksum
How to use checksums
ed65fe5012d7f768987e19618d15ea92f8d6a61017439d0701bda47b1a0f01ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.5

Release history Release notifications | RSS feed

This release

3.5.1 This release

2 release files

3.5

2 release files

3.4

2 release files

3.3

2 release files

3.2

2 release files

3.1

2 release files

3.0

2 release files

2.13

2 release files

2.12

2 release files

2.11

2 release files

2.10

2 release files

2.9

2 release files

2.8

2 release files

2.7

2 release files

2.6

2 release files

2.5

2 release files

2.4

2 release files

2.3

2 release files

2.2.1

2 release files

2.2

2 release files

2.1.2

2 release files

2.1.1

2 release files

2.1

2 release files

2.0

2 release files

1.1.2

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page