QuantMathematics [Achira Meegasthanne]

QuantMathematics
QuantMathematics is a reusable Pine Script mathematical library designed to provide a broad collection of calculation functions for quantitative analysis, trading systems, indicators, strategies, and custom Pine Script development.
The library contains a large set of reusable mathematical operations that can be imported and used inside other Pine Script projects.
🔹 CORE MATHEMATICS
Includes fundamental mathematical functions such as:
• Addition
• Subtraction
• Multiplication
• Division
• Sum
• Difference
• Product
• Quotient
• Average
• Arithmetic Mean
• Midpoint
• Half Sum
• Half Difference
• Double Sum
• Double Difference
• Triple Sum
• Triple Difference
These functions provide simple building blocks for creating more complex calculations.
📊 RATIOS & PERCENTAGES
The library includes multiple functions for analyzing relationships between two values.
Available calculations include:
• Ratio
• Relative Ratio
• Reverse Relative Ratio
• Share of Total
• Relative Share
• Percentage
• Percentage Change
• Percentage Increase
• Percentage Decrease
• Percentage Difference
• Relative Change
• Relative Difference
• Ratio Percentage
• Reverse Ratio Percentage
• Balance Percentage
• Contribution Percentage
• Complementary Percentage
• Gain Percentage
• Loss Percentage
• Appreciation Percentage
• Depreciation Percentage
These functions can be useful for comparing price, volume, performance, risk, allocation, and other quantitative values.
📈 PRICE & PERFORMANCE CALCULATIONS
QuantMathematics provides functions for calculating price movement and performance metrics.
Includes:
• Price Return
• Simple Return
• Return Percentage
• Price Change
• Price Change Percentage
• Relative Price Change
• Price Displacement
• Momentum
• Momentum Percentage
• Price Position
• Price Range
• Range Ratio
• Range Percentage
• Appreciation
• Depreciation
• Gain Ratio
• Loss Ratio
• Profit Ratio
• Drawdown Ratio
• Drawdown Percentage
• Recovery Ratio
These functions can be used as components inside trading strategies and quantitative indicators.
⚖️ RISK & REWARD
The library also includes calculations useful for basic risk and reward analysis.
Available functions include:
• Risk Reward
• Reward Risk
• Break-Even Difference
• Exposure Ratio
• Leverage Ratio
• Capital Ratio
• Utilization Ratio
• Efficiency Ratio
• Performance Ratio
• Recovery Ratio
• Drawdown Ratio
• Profit Ratio
• Loss Ratio
These functions can be integrated into custom risk-management and strategy calculations.
📐 ALGEBRA & POLYNOMIAL FUNCTIONS
QuantMathematics includes a wide range of algebraic operations.
Examples include:
• Square
• Cube
• Square Sum
• Square Difference
• Sum of Squares
• Difference of Squares
• Sum of Cubes
• Difference of Cubes
• Product of Sum and Difference
• Quadratic Sum
• Quadratic Difference
• Quadratic Balance
• Reverse Quadratic Balance
• Bilinear Sum
• Bilinear Difference
• Bilinear Balance
• Cubic Sum
• Cubic Difference
• Cubic Balance
• Reverse Cubic Balance
• Cubic Product
• Polynomial Sum
• Polynomial Difference
• Reverse Polynomial
• Mixed Polynomial
These functions can be combined to build custom mathematical models and quantitative formulas.
🔄 NORMALIZATION & BALANCE
The library provides multiple normalization and balance calculations for comparing values on a relative basis.
Includes:
• Normalized Difference
• Normalized Sum
• Normalized Value
• Normalized Product
• Normalized Square
• Normalized Cube
• Normalized Difference Square
• Normalized Sum Square
• Balance
• Balance Ratio
• Balance Index
• Market Balance
• Weighted Balance
• Pressure Ratio
• Relative Position
• Relative Spread
• Normalized Spread
These functions can be useful when building normalized quantitative models.
📊 WEIGHTED & RELATIVE CALCULATIONS
The library includes weighted calculations for creating customized mathematical relationships.
Examples:
• Weighted Mean
• Reverse Weighted Mean
• Weighted Difference
• Weighted Sum
• Weighted Balance
• Weighted Center
• Weighted Midpoint
• Weighted Ratio
• Reverse Weighted Ratio
• Weighted Spread
• Relative Share
• Complementary Share
• Market Share
• Reverse Market Share
These functions allow developers to assign different mathematical importance to input values.
🔢 RECIPROCAL & INVERSE FUNCTIONS
QuantMathematics also provides reciprocal and inverse calculations.
Includes:
• Reciprocal Ratio
• Reciprocal Balance
• Reciprocal Sum
• Reciprocal Difference
• Reciprocal Average
• Reciprocal Product
• Inverse Ratio
• Inverse Difference
• Inverse Sum
• Inverse Average
• Combined Ratio
• Ratio Difference
• Ratio Average
• Ratio Spread
• Reverse Ratio Spread
These functions can be useful for mathematical transformations and custom quantitative formulas.
📐 SCALING & FRACTIONAL FUNCTIONS
The library contains functions for scaling values using common fractions and multipliers.
Includes:
• Scaled Difference
• Scaled Sum
• Scaled Product
• Scaled Ratio
• Quarter Sum
• Quarter Difference
• Three Quarter Sum
• Three Quarter Difference
• One Third Sum
• One Third Difference
• Two Thirds Sum
• Two Thirds Difference
• Three Halves Sum
• Three Halves Difference
• Five Halves Sum
• Five Halves Difference
These functions provide convenient building blocks for custom mathematical models.
📈 TREND & MOVEMENT FUNCTIONS
QuantMathematics includes simple functions for analyzing movement and directional relationships.
Includes:
• Slope
• Gradient
• Trend Change
• Momentum
• Price Displacement
• Price Change
• Relative Change
• Expansion
• Contraction
• Extrapolation
• Linear Interpolation
• Deviation
• Spread
• Volatility Range
These can be incorporated into custom trend and quantitative calculations.
🧮 STATISTICAL-STYLE CALCULATIONS
The library also provides several functions that can be used as components of statistical calculations.
Examples include:
• Harmonic Mean
• Geometric Mean
• Root Mean Square
• Covariance Term
• Correlation Term
• Variance Term
• Deviation Square
• Mean Deviation
• Absolute Deviation
• Volatility Range
• Relative Spread
• Normalized Spread
These functions can serve as building blocks for more advanced quantitative models.
🏦 MARKET & CAPITAL METRICS
The library contains additional functions covering:
• Market Ratio
• Market Balance
• Market Share
• Capital Ratio
• Allocation
• Allocation Ratio
• Reserve Ratio
• Exposure Ratio
• Leverage Ratio
• Capacity Ratio
• Capacity Gap
• Utilization
• Utilization Gap
• Performance Gap
• Benchmark Difference
• Benchmark Ratio
• Benchmark Deviation
• Benchmark Percentage
These functions can be adapted for financial and quantitative calculations depending on how the inputs are defined.
🔧 DESIGNED AS A REUSABLE LIBRARY
QuantMathematics is declared as a Pine Script library, with its mathematical functions exported for use in other Pine Script projects.
This makes the library suitable for:
• Custom Indicators
• Trading Strategies
• Quantitative Models
• Mathematical Tools
• Risk Calculations
• Price Analysis
• Portfolio Calculations
• Research Scripts
• Educational Projects
• Custom Pine Script Libraries
🧠 EXAMPLE
The library can also be used for mathematical demonstrations.
The included example demonstrates the Pythagorean Theorem using a 3-4-5 triangle and the sum_of_squares function:
x² + y² = c²
For x = 3 and y = 4:
3² + 4² = 5²
The example also visualizes the triangle directly on the TradingView chart.
⚠️ IMPORTANT NOTE
QuantMathematics is a mathematical utility library, not a standalone trading strategy or guaranteed trading-signal system.
The functions perform mathematical calculations based on the values supplied to them. Any trading interpretation, signal generation, risk calculation, or financial decision made using this library depends on the implementation of the importing script.
Always validate your calculations and thoroughly test any trading system before using it with real capital.
Build the mathematics first. Build the strategy on top of it.
QuantMathematics is a reusable Pine Script mathematical library designed to provide a broad collection of calculation functions for quantitative analysis, trading systems, indicators, strategies, and custom Pine Script development.
The library contains a large set of reusable mathematical operations that can be imported and used inside other Pine Script projects.
🔹 CORE MATHEMATICS
Includes fundamental mathematical functions such as:
• Addition
• Subtraction
• Multiplication
• Division
• Sum
• Difference
• Product
• Quotient
• Average
• Arithmetic Mean
• Midpoint
• Half Sum
• Half Difference
• Double Sum
• Double Difference
• Triple Sum
• Triple Difference
These functions provide simple building blocks for creating more complex calculations.
📊 RATIOS & PERCENTAGES
The library includes multiple functions for analyzing relationships between two values.
Available calculations include:
• Ratio
• Relative Ratio
• Reverse Relative Ratio
• Share of Total
• Relative Share
• Percentage
• Percentage Change
• Percentage Increase
• Percentage Decrease
• Percentage Difference
• Relative Change
• Relative Difference
• Ratio Percentage
• Reverse Ratio Percentage
• Balance Percentage
• Contribution Percentage
• Complementary Percentage
• Gain Percentage
• Loss Percentage
• Appreciation Percentage
• Depreciation Percentage
These functions can be useful for comparing price, volume, performance, risk, allocation, and other quantitative values.
📈 PRICE & PERFORMANCE CALCULATIONS
QuantMathematics provides functions for calculating price movement and performance metrics.
Includes:
• Price Return
• Simple Return
• Return Percentage
• Price Change
• Price Change Percentage
• Relative Price Change
• Price Displacement
• Momentum
• Momentum Percentage
• Price Position
• Price Range
• Range Ratio
• Range Percentage
• Appreciation
• Depreciation
• Gain Ratio
• Loss Ratio
• Profit Ratio
• Drawdown Ratio
• Drawdown Percentage
• Recovery Ratio
These functions can be used as components inside trading strategies and quantitative indicators.
⚖️ RISK & REWARD
The library also includes calculations useful for basic risk and reward analysis.
Available functions include:
• Risk Reward
• Reward Risk
• Break-Even Difference
• Exposure Ratio
• Leverage Ratio
• Capital Ratio
• Utilization Ratio
• Efficiency Ratio
• Performance Ratio
• Recovery Ratio
• Drawdown Ratio
• Profit Ratio
• Loss Ratio
These functions can be integrated into custom risk-management and strategy calculations.
📐 ALGEBRA & POLYNOMIAL FUNCTIONS
QuantMathematics includes a wide range of algebraic operations.
Examples include:
• Square
• Cube
• Square Sum
• Square Difference
• Sum of Squares
• Difference of Squares
• Sum of Cubes
• Difference of Cubes
• Product of Sum and Difference
• Quadratic Sum
• Quadratic Difference
• Quadratic Balance
• Reverse Quadratic Balance
• Bilinear Sum
• Bilinear Difference
• Bilinear Balance
• Cubic Sum
• Cubic Difference
• Cubic Balance
• Reverse Cubic Balance
• Cubic Product
• Polynomial Sum
• Polynomial Difference
• Reverse Polynomial
• Mixed Polynomial
These functions can be combined to build custom mathematical models and quantitative formulas.
🔄 NORMALIZATION & BALANCE
The library provides multiple normalization and balance calculations for comparing values on a relative basis.
Includes:
• Normalized Difference
• Normalized Sum
• Normalized Value
• Normalized Product
• Normalized Square
• Normalized Cube
• Normalized Difference Square
• Normalized Sum Square
• Balance
• Balance Ratio
• Balance Index
• Market Balance
• Weighted Balance
• Pressure Ratio
• Relative Position
• Relative Spread
• Normalized Spread
These functions can be useful when building normalized quantitative models.
📊 WEIGHTED & RELATIVE CALCULATIONS
The library includes weighted calculations for creating customized mathematical relationships.
Examples:
• Weighted Mean
• Reverse Weighted Mean
• Weighted Difference
• Weighted Sum
• Weighted Balance
• Weighted Center
• Weighted Midpoint
• Weighted Ratio
• Reverse Weighted Ratio
• Weighted Spread
• Relative Share
• Complementary Share
• Market Share
• Reverse Market Share
These functions allow developers to assign different mathematical importance to input values.
🔢 RECIPROCAL & INVERSE FUNCTIONS
QuantMathematics also provides reciprocal and inverse calculations.
Includes:
• Reciprocal Ratio
• Reciprocal Balance
• Reciprocal Sum
• Reciprocal Difference
• Reciprocal Average
• Reciprocal Product
• Inverse Ratio
• Inverse Difference
• Inverse Sum
• Inverse Average
• Combined Ratio
• Ratio Difference
• Ratio Average
• Ratio Spread
• Reverse Ratio Spread
These functions can be useful for mathematical transformations and custom quantitative formulas.
📐 SCALING & FRACTIONAL FUNCTIONS
The library contains functions for scaling values using common fractions and multipliers.
Includes:
• Scaled Difference
• Scaled Sum
• Scaled Product
• Scaled Ratio
• Quarter Sum
• Quarter Difference
• Three Quarter Sum
• Three Quarter Difference
• One Third Sum
• One Third Difference
• Two Thirds Sum
• Two Thirds Difference
• Three Halves Sum
• Three Halves Difference
• Five Halves Sum
• Five Halves Difference
These functions provide convenient building blocks for custom mathematical models.
📈 TREND & MOVEMENT FUNCTIONS
QuantMathematics includes simple functions for analyzing movement and directional relationships.
Includes:
• Slope
• Gradient
• Trend Change
• Momentum
• Price Displacement
• Price Change
• Relative Change
• Expansion
• Contraction
• Extrapolation
• Linear Interpolation
• Deviation
• Spread
• Volatility Range
These can be incorporated into custom trend and quantitative calculations.
🧮 STATISTICAL-STYLE CALCULATIONS
The library also provides several functions that can be used as components of statistical calculations.
Examples include:
• Harmonic Mean
• Geometric Mean
• Root Mean Square
• Covariance Term
• Correlation Term
• Variance Term
• Deviation Square
• Mean Deviation
• Absolute Deviation
• Volatility Range
• Relative Spread
• Normalized Spread
These functions can serve as building blocks for more advanced quantitative models.
🏦 MARKET & CAPITAL METRICS
The library contains additional functions covering:
• Market Ratio
• Market Balance
• Market Share
• Capital Ratio
• Allocation
• Allocation Ratio
• Reserve Ratio
• Exposure Ratio
• Leverage Ratio
• Capacity Ratio
• Capacity Gap
• Utilization
• Utilization Gap
• Performance Gap
• Benchmark Difference
• Benchmark Ratio
• Benchmark Deviation
• Benchmark Percentage
These functions can be adapted for financial and quantitative calculations depending on how the inputs are defined.
🔧 DESIGNED AS A REUSABLE LIBRARY
QuantMathematics is declared as a Pine Script library, with its mathematical functions exported for use in other Pine Script projects.
This makes the library suitable for:
• Custom Indicators
• Trading Strategies
• Quantitative Models
• Mathematical Tools
• Risk Calculations
• Price Analysis
• Portfolio Calculations
• Research Scripts
• Educational Projects
• Custom Pine Script Libraries
🧠 EXAMPLE
The library can also be used for mathematical demonstrations.
The included example demonstrates the Pythagorean Theorem using a 3-4-5 triangle and the sum_of_squares function:
x² + y² = c²
For x = 3 and y = 4:
3² + 4² = 5²
The example also visualizes the triangle directly on the TradingView chart.
⚠️ IMPORTANT NOTE
QuantMathematics is a mathematical utility library, not a standalone trading strategy or guaranteed trading-signal system.
The functions perform mathematical calculations based on the values supplied to them. Any trading interpretation, signal generation, risk calculation, or financial decision made using this library depends on the implementation of the importing script.
Always validate your calculations and thoroughly test any trading system before using it with real capital.
Build the mathematics first. Build the strategy on top of it.
Wyłączenie odpowiedzialności
Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.
Wyłączenie odpowiedzialności
Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.