Skip to content

Instantly share code, notes, and snippets.

@ohdearquant
ohdearquant / recursiveUvalidator.ipynb
Last active April 24, 2024 00:58
recursive U validator, mixtrure of experts, evolving agents
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Intertemporal Capital Asset pricing model

by: Haiyang Li | ocean@quantoceanli.com | 2023-08-08

Motivation

How to live a good life is an area of interest for economists, and they have set up a framework on how to approach this problem. According to the rational choice theory, under a set of assumptions, a decision maker will choose the option that maximize their expected outcome (measured in utility), when making decisions among different uncertain options.

Understanding Functions in Python - 1

According to wikipedia,

"In mathematics, a function from a set X to a set Y assigns to each element of X exactly one element of Y. The set X is called the domain of the function and the set Y is called the codomain of the function"

A function in mathematics can be expressed as, $$f: X \to Y$$

Automatic Differentiation in Deep Learning

Introduction

Automatic Differentiation, often shortened as autograd, plays an instrumental role in most modern deep learning frameworks. Its primary function is to simplify the process of calculating derivatives, an essential part of optimization algorithms used in deep learning model training. The manual computation of derivatives can become tedious and susceptible to errors, particularly as model complexity increases. Autograd addresses this challenge by constructing a computational graph during the data processing phase, mapping the dependencies between different values.

Autograd in Practice

When it comes to derivative computation, autograd uses the chain rule and works backwards through the computational graph, a process referred to as backpropagation. While backpropagation remains a widely used method for gradient computations in deep learning, it's not the only option. For example, the Julia programming language employs forward propagation, hig

Introduction

Linear algebra plays a pivotal role in machine learning (ML), forming the backbone for many ML algorithms and models. Concepts like scalars, vectors, and matrices are fundamental to manipulating datasets and performing large-scale mathematical operations. Understanding these concepts is the first step towards creating complex models for ML applications.

Scalars

In mathematics, individual numbers are often manipulated. These individual values are formally referred to as scalars. Scalars are usually represented by lower-case letters like $x$, $y$, and $z$. The expression $x \in \mathbb{R}$ denotes that $x$ is a real-valued scalar, with $\in$ representing membership in a set. In the context of Python and PyTorch, scalars are implemented as tensors that contain only one element.

As the basic units of mathematical manipulation in machine learning, scalars could represent simple features in a dataset or parameters in a model. For example, in a **linear regressio

Ch2: Setting up Your Python Environment

The first step in starting with Python is establishing a development environment. We will be using Anaconda, a popular data science platform that provides a streamlined experience for Python programming among others. Also, we will be using VS code as IDE to write, debug, test, and run codes, as it's free but very powerful and versatile.

Getting Started with Anaconda

Anaconda is more than a Python distribution - it's a comprehensive toolkit for data scientists. It simplifies the management of Python environments and packages and comes bundled with a variety of powerful libraries and tools.

Installation

Ch 1 - Introduction to Python

1.1 Python: A Vital Tool in the Finance Industry

Python, introduced by Guido van Rossum in 1991, has become an essential tool in the finance industry. This is attributable to Python's range of applications and simple yet powerful syntax. Python allows programmers to express their ideas compactly, offering significant time savings compared to other programming languages such as C++ or Java.

The strength of Python comes from its large, active community of developers who have expanded Python's functionality to meet diverse needs. Python is renowned for its 'batteries-included' principle, which refers to the comprehensive standard library that comes with Python. This library includes tools for creating graphical user interfaces, connecting to web servers, handling JSON data, and more. Python suits various tasks, from web development and data analytics to machine learning.

Python's popularity in finance stems from its wealth of libraries, clean syntax, and versatility. Finan

Optimized Stock Trading Strategy: An RSI Backtest Framework

This project presents a robust, data-driven Python framework for backtesting and optimizing a Relative Strength Index (RSI) based trading strategy. The framework simplifies technical analysis and aids in making effective trading decisions based on market momentum. It offers a comprehensive system capable of backtesting, optimizing, and visualizing a trading strategy using the Relative Strength Index (RSI), a well-recognized momentum indicator in technical analysis.

Key Features

  • RSI-Based Trading Strategy: This strategy generates 'buy' signals when a stock is potentially oversold and 'sell' signals when it's possibly overbought. It's based on the careful selection and optimization of RSI thresholds and time periods.
  • Efficient Parameter Optimization: This approach aims to strike a balance between high returns and reduced transaction frequency, optimizing the strategy's effectiveness.
  • Comprehensive Python Classes: A suite of P