diff --git a/.gitignore b/.gitignore index 01f2b32..7a6533e 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ pom.xml.asc /.prepl-port .hgignore .hg/ +Debugging/ profiles.clj specs.clj diff --git a/examples/Debugging/.ipynb_checkpoints/Plotting time range-checkpoint.ipynb b/examples/Debugging/.ipynb_checkpoints/Plotting time range-checkpoint.ipynb deleted file mode 100644 index 4271637..0000000 --- a/examples/Debugging/.ipynb_checkpoints/Plotting time range-checkpoint.ipynb +++ /dev/null @@ -1,559 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "nil" - ] - }, - "execution_count": 1, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "; import libraries from kernel\n", - "(ns clojure-backtesting.demo\n", - " (:require [clojure.test :refer :all]\n", - " [clojure-backtesting.data :refer :all]\n", - " [clojure-backtesting.order :refer :all]\n", - " [clojure-backtesting.evaluate :refer :all]\n", - " [clojure-backtesting.plot :refer :all]\n", - " [clojure-backtesting.counter :refer :all]\n", - " ;;[clojure-backtesting.parameters :refer :all]\n", - " [clojure.string :as str]\n", - " [clojure.pprint :as pprint]\n", - " [java-time :as t]\n", - " [clojupyter.kernel.version :as ver]\n", - " [clojupyter.misc.helper :as helper]\n", - " ) ;; require all libriaries from core\n", - " (:use clojure.pprint)\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [], - "source": [ - "; path to dataset = \"../resources/CRSP-extract.csv\"\n", - "; change it to the relative to your own dataset\n", - ";\n", - "(reset! data-set (add-aprc (read-csv-row \"../../resources/CRSP-extract.csv\")));" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [], - "source": [ - ";; initialise with current date and initial capital (= $10000)\n", - "(init-portfolio \"1980-12-16\" 10000);" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Test range of 1 year" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "26.093628318359524\n", - "Order: 1980-12-17 | AAPL | 50.\n", - "Buy 50 stocks of AAPL on 1980-12-16\n", - "22.729204943748716\n", - "Order: 1981-12-11 | AAPL | -50.\n", - "Sell 10 stocks of AAPL on 1981-12-10\n" - ] - }, - { - "data": { - "text/plain": [ - "nil" - ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - ";; define the \"time span\", i.e. to trade in the coming 250 days \n", - "(def num-of-days (atom 250)) \n", - "\n", - "(while (pos? @num-of-days)\n", - " (do \n", - " ;; write your trading strategy here\n", - " (if (= 250 @num-of-days)\n", - " (do\n", - " (order \"AAPL\" 50) ; buy 50 stocks\n", - " (println ((fn [date] (str \"Buy 50 stocks of AAPL on \" date)) (get-date)))\n", - " )\n", - " )\n", - " (if (= 1 @num-of-days)\n", - " (do\n", - " (order \"AAPL\" -50) ; sell 10 stocks\n", - " (println ((fn [date] (str \"Sell 10 stocks of AAPL on \" date)) (get-date)))\n", - " )\n", - " )\n", - " \n", - " (update-eval-report (get-date))\n", - " \n", - " ; move on to the next trading day\n", - " (next-date)\n", - " \n", - " ; decrement counter\n", - " (swap! num-of-days dec)\n", - " )\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "| :date | :tic | :price | :quantity | :reference |\n", - "|------------+------+---------+-----------+------------|\n", - "| 1980-12-17 | AAPL | 25.9375 | 50 | 2 |\n", - "| 1981-12-11 | AAPL | 18.875 | -50 | 251 |\n" - ] - }, - { - "data": { - "text/plain": [ - "nil" - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "(pprint/print-table (deref order-record))" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "| :date | :tot-value | :daily-ret | :loan | :leverage |\n", - "|------------+------------+------------+-------+-----------|\n", - "| 1980-12-16 | $10000 | 0.00% | $0.00 | 0.00% |\n", - "| 1980-12-17 | $10007 | 0.00% | $nu | nu% |\n", - "| 1981-12-11 | $9646 | -0.04% | $nu | nu% |\n" - ] - }, - { - "data": { - "text/plain": [ - "nil" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - ";; view portfolio value and return\n", - "(view-portfolio-record)" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "| :date | :pnl-pt | :ret-da | :ret-r | :ret-tot | :sharpe-e | :sharpe-r | :tot-val | :vol-e | :vol-r |\n", - "|------------+---------+---------+--------+----------+-----------+-----------+----------+--------+--------|\n", - "| 1980-12-16 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1980-12-17 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1980-12-18 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1980-12-19 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1980-12-22 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1980-12-23 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1980-12-24 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1980-12-26 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1980-12-29 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1980-12-30 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1980-12-31 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-02 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-05 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-06 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-07 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-08 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-09 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-12 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-13 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-14 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-15 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-16 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-19 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-20 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-21 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-22 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-23 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-26 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-27 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-28 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-29 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-30 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-02 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-03 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-04 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-05 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-06 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-09 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-10 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-11 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-12 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-13 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-17 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-18 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-19 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-20 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-23 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-24 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-25 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-26 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-27 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-02 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-03 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-04 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-05 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-06 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-09 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-10 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-11 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-12 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-13 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-16 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-17 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-18 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-19 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-20 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-23 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-24 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-25 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-26 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-27 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-30 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-31 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-01 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "| 1981-04-02 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-03 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-06 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-07 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-08 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-09 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-10 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-13 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-14 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-15 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-16 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-20 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-21 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-22 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-23 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-24 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-27 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-28 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-29 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-30 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-01 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-04 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-05 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-06 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-07 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-08 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-11 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-12 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-13 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-14 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-15 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-18 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-19 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-20 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-21 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-22 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-26 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-27 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-28 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-29 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-01 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-02 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-03 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-04 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-05 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-08 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-09 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-10 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-11 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-12 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-15 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-16 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-17 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-18 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-19 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-22 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-23 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-24 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-25 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-26 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-29 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-30 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-01 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-02 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-06 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-07 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-08 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-09 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-10 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-13 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-14 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-15 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-16 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-17 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-20 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-21 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "| 1981-07-22 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-23 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-24 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-27 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-28 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-29 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-30 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-31 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-03 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-04 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-05 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-06 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-07 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-10 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-11 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-12 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-13 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-14 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-17 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-18 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-19 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-20 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-21 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-24 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-25 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-26 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-27 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-28 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-31 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-01 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-02 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-03 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-04 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-08 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-09 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-10 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-11 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-14 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-15 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-16 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-17 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-18 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-21 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-22 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-23 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-24 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-25 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-28 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-29 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-30 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-01 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-02 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-05 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-06 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-07 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-08 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-09 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-12 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-13 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-14 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-15 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-16 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-19 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-20 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-21 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-22 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-23 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-26 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-27 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-28 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-29 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-30 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-02 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-03 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-04 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-05 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "| 1981-11-06 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-09 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-10 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-11 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-12 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-13 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-16 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-17 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-18 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-19 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-20 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-23 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-24 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-25 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-27 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-30 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-12-01 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-12-02 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-12-03 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-12-04 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-12-07 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-12-08 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-12-09 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-12-10 | $-176 | -3.67% | -0.00% | -3.60% | -1.68% | -0.00% | $9646 | 2.14% | 0.34% |\n" - ] - }, - { - "data": { - "text/plain": [ - "nil" - ] - }, - "execution_count": 16, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "(eval-report)" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "
\n", - "
\n", - " \n", - "
\n", - " " - ] - }, - "execution_count": 13, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "(def data (deref portfolio-value))\n", - "\n", - "; Add legend name to series\n", - "(def data-to-plot\n", - " (map #(assoc % :plot \"portfolio\")\n", - " data))\n", - "\n", - "(plot data-to-plot :plot :date :daily-ret)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Clojure (backtesting_clojure)", - "language": "clojure", - "name": "backtesting_clojure" - }, - "language_info": { - "file_extension": ".clj", - "mimetype": "text/x-clojure", - "name": "clojure", - "version": "1.10.1" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/examples/Debugging/Plotting time range.ipynb b/examples/Debugging/Plotting time range.ipynb deleted file mode 100644 index d0b7966..0000000 --- a/examples/Debugging/Plotting time range.ipynb +++ /dev/null @@ -1,610 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 17, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "nil" - ] - }, - "execution_count": 17, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "; import libraries from kernel\n", - "(ns clojure-backtesting.demo\n", - " (:require [clojure.test :refer :all]\n", - " [oz.notebook.clojupyter :as oz]\n", - " [clojure-backtesting.data :refer :all]\n", - " [clojure-backtesting.order :refer :all]\n", - " [clojure-backtesting.evaluate :refer :all]\n", - " [clojure-backtesting.plot :refer :all]\n", - " [clojure-backtesting.counter :refer :all]\n", - " ;;[clojure-backtesting.parameters :refer :all]\n", - " [clojure.string :as str]\n", - " [clojure.pprint :as pprint]\n", - " [java-time :as t]\n", - " [clojupyter.kernel.version :as ver]\n", - " [clojupyter.misc.helper :as helper]\n", - " ) ;; require all libriaries from core\n", - " (:use clojure.pprint)\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [], - "source": [ - "; path to dataset = \"../resources/CRSP-extract.csv\"\n", - "; change it to the relative to your own dataset\n", - ";\n", - "(reset! data-set (add-aprc (read-csv-row \"../../resources/CRSP-extract.csv\")));" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [], - "source": [ - ";; initialise with current date and initial capital (= $10000)\n", - "(init-portfolio \"1980-12-16\" 10000);" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Test range of 1 year" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Buy 50 stocks of AAPL on 1980-12-16\n", - "Sell 10 stocks of AAPL on 1981-12-10\n" - ] - }, - { - "data": { - "text/plain": [ - "nil" - ] - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - ";; define the \"time span\", i.e. to trade in the coming 250 days \n", - "(def num-of-days (atom 250)) \n", - "\n", - "(while (pos? @num-of-days)\n", - " (do \n", - " ;; write your trading strategy here\n", - " (if (= 250 @num-of-days)\n", - " (do\n", - " (order \"AAPL\" 50) ; buy 50 stocks\n", - " (println ((fn [date] (str \"Buy 50 stocks of AAPL on \" date)) (get-date)))\n", - " )\n", - " )\n", - " (if (= 1 @num-of-days)\n", - " (do\n", - " (order \"AAPL\" -50) ; sell 10 stocks\n", - " (println ((fn [date] (str \"Sell 10 stocks of AAPL on \" date)) (get-date)))\n", - " )\n", - " )\n", - " \n", - " (update-eval-report (get-date))\n", - " \n", - " ; move on to the next trading day\n", - " (next-date)\n", - " \n", - " ; decrement counter\n", - " (swap! num-of-days dec)\n", - " )\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "| :date | :tic | :price | :quantity | :reference |\n", - "|------------+------+---------+-----------+------------|\n", - "| 1980-12-17 | AAPL | 25.9375 | 50 | 1 |\n", - "| 1981-12-11 | AAPL | 18.875 | -50 | 1 |\n" - ] - }, - { - "data": { - "text/plain": [ - "nil" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "(pprint/print-table (deref order-record))" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "| :date | :tot-value | :daily-ret | :loan | :leverage |\n", - "|------------+------------+------------+-------+-----------|\n", - "| 1980-12-16 | $10000 | 0.00% | $0.00 | 0.00% |\n", - "| 1980-12-17 | $10007 | 0.00% | $0.00 | 0.00% |\n", - "| 1981-12-11 | $9646 | -0.04% | $0.00 | 0.00% |\n" - ] - }, - { - "data": { - "text/plain": [ - "nil" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - ";; view portfolio value and return\n", - "(view-portfolio-record)" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "| :date | :pnl-pt | :ret-da | :ret-r | :ret-tot | :sharpe-e | :sharpe-r | :tot-val | :vol-e | :vol-r |\n", - "|------------+---------+---------+--------+----------+-----------+-----------+----------+--------+--------|\n", - "| 1980-12-16 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1980-12-17 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1980-12-18 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1980-12-19 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1980-12-22 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1980-12-23 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1980-12-24 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1980-12-26 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1980-12-29 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1980-12-30 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1980-12-31 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-02 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-05 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-06 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-07 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-08 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-09 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-12 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-13 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-14 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-15 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-16 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-19 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-20 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-21 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-22 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-23 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-26 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-27 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-28 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-29 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-01-30 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-02 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-03 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-04 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-05 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-06 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-09 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-10 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-11 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-12 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-13 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-17 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-18 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-19 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-20 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-23 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-24 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-25 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-26 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-02-27 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-02 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-03 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-04 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-05 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-06 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-09 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-10 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-11 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-12 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-13 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-16 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-17 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-18 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-19 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-20 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-23 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-24 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-25 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-26 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-27 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-30 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-03-31 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-01 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "| 1981-04-02 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-03 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-06 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-07 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-08 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-09 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-10 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-13 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-14 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-15 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-16 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-20 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-21 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-22 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-23 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-24 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-27 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-28 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-29 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-04-30 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-01 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-04 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-05 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-06 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-07 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-08 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-11 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-12 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-13 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-14 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-15 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-18 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-19 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-20 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-21 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-22 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-26 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-27 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-28 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-05-29 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-01 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-02 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-03 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-04 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-05 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-08 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-09 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-10 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-11 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-12 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-15 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-16 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-17 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-18 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-19 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-22 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-23 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-24 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-25 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-26 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-29 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-06-30 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-01 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-02 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-06 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-07 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-08 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-09 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-10 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-13 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-14 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-15 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-16 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-17 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-20 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-21 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "| 1981-07-22 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-23 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-24 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-27 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-28 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-29 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-30 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-07-31 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-03 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-04 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-05 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-06 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-07 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-10 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-11 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-12 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-13 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-14 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-17 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-18 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-19 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-20 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-21 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-24 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-25 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-26 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-27 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-28 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-08-31 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-01 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-02 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-03 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-04 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-08 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-09 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-10 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-11 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-14 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-15 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-16 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-17 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-18 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-21 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-22 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-23 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-24 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-25 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-28 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-29 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-09-30 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-01 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-02 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-05 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-06 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-07 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-08 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-09 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-12 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-13 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-14 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-15 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-16 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-19 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-20 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-21 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-22 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-23 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-26 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-27 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-28 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-29 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-10-30 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-02 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-03 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-04 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-05 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "| 1981-11-06 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-09 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-10 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-11 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-12 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-13 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-16 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-17 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-18 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-19 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-20 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-23 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-24 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-25 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-27 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-11-30 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-12-01 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-12-02 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-12-03 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-12-04 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-12-07 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-12-08 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-12-09 | $7 | 0.08% | 0.00% | 0.08% | 1.41% | 0.22% | $10007 | 0.06% | 0.01% |\n", - "| 1981-12-10 | $-176 | -3.67% | -0.00% | -3.60% | -1.68% | -0.00% | $9646 | 2.14% | 0.34% |\n" - ] - }, - { - "data": { - "text/plain": [ - "nil" - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "(eval-report)" - ] - }, - { - "cell_type": "code", - "execution_count": 20, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "#'clojure-backtesting.demo/plot-new" - ] - }, - "execution_count": 20, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "\n", - "(defn plot-new\n", - " \"this is the function that allows the users to plot charts,\"\n", - " ([dataset series x y ]\n", - " (oz/view!\n", - " { :width 800 :height 500 ;adjust the graph size\n", - " :data {:values dataset}\n", - " :encoding {:x {:field x :type \"temporal\" :timeUnit \"yearmonthdate\"};\"field\" means the x-axis name, \"type\" asking what's the data type of x-axis values; choosing from \"quantity\"/\"nominal\"/\"temporal\" \n", - " :y {:field y :type \"quantitative\"}\n", - " :color {:field series :type \"nominal\"} ;if it's only 1 line, no need this\n", - " } \n", - " :mark \"line\"\n", - " }\n", - " ))\n", - " \n", - " ([dataset series x y1 y2] ;y1 & y2 should be key for values to be plotted, e.g. :tot-value or :daily-ret\n", - " (oz/view!\n", - " { :width 800 :height 500 ;adjust the graph size\n", - " :data {:values dataset}\n", - " :encoding {:x {:field x :type \"temporal\" :timeUnit \"yearmonthdate\"} ;\"field\" means the x-axis name, \"type\" asking what's the data type of x-axis values; choosing from \"quantity\"/\"nominal\"/\"temporal\" \n", - " :color {:field series :type \"nominal\"} ;if it's only 1 line, no need this\n", - " } \n", - " :layer [\n", - " {:mark {:type \"line\"}\n", - " :encoding {:y {:field y1 :type \"quantitative\"}\n", - " :color {:field series :type \"nominal\"}}\n", - " } \n", - " {:mark {:type \"line\"}\n", - " :encoding {:y {:field y2 :type \"quantitative\"}\n", - " :color {:field series :type \"nominal\"}}\n", - " }]\n", - " :resolve {:scale {:y \"independent\"}}\n", - " }\n", - " ))\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 21, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "
\n", - "
\n", - " \n", - "
\n", - " " - ] - }, - "execution_count": 21, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "(def data (deref portfolio-value))\n", - "\n", - "; Add legend name to series\n", - "(def data-to-plot\n", - " (map #(assoc % :plot \"portfolio\")\n", - " data))\n", - "\n", - "(plot-new data-to-plot :plot :date :daily-ret)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Clojure (backtesting_clojure)", - "language": "clojure", - "name": "backtesting_clojure" - }, - "language_info": { - "file_extension": ".clj", - "mimetype": "text/x-clojure", - "name": "clojure", - "version": "1.10.1" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -}