PHPackages                             michalbrauner/forex-calculator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. michalbrauner/forex-calculator

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

michalbrauner/forex-calculator
==============================

Library in order to make calculations related to Forex. It provides basic calculators that can be used to improve your money management.

v1.0.4(9y ago)0151MITPHPPHP &gt;= 7.0.0

Since Dec 28Pushed 7y ago1 watchersCompare

[ Source](https://github.com/michalbrauner/forex-calculator)[ Packagist](https://packagist.org/packages/michalbrauner/forex-calculator)[ RSS](/packages/michalbrauner-forex-calculator/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (5)Dependencies (2)Versions (6)Used By (0)

[![Build Status](https://camo.githubusercontent.com/f77b5ae875aa8ae4419485a860e40a768b939992ffbcbc18f13c04fb52b06e58/68747470733a2f2f696d672e736869656c64732e696f2f736869707061626c652f3538343564346536333037623166306630303466623534642f6d61737465722e737667)](https://app.shippable.com/projects/5845d4e6307b1f0f004fb54d/status/dashboard)

About
-----

[](#about)

Forex-calculator is a library to make calculations related to Forex. It provides basic calculators that can be used to improve your money management. Library requires **PHP 7**.

Installation
------------

[](#installation)

```
composer install michalbrauner/forex-calculator:^v1.0

```

Usage
-----

[](#usage)

### Currency converter

[](#currency-converter)

```
$currencyConverter = new \ForexCalculator\Services\CurrencyConverter(
  new \ForexCalculator\DataProviders\YahooDataProvider(new \GuzzleHttp\Client())
);

# Convert 100 eur to usd

$convertedValue = $currencyConverter->convertToCurrency('eur', 'usd', 100);
```

### Profit, loss and RRR calculator

[](#profit-loss-and-rrr-calculator)

```
# Create calculator factory

$tradeAttributesCalculatorFactory = new \ForexCalculator\Services\TradeAttributesByTradeSizeCalculatorFactory(
    new \ForexCalculator\DataProviders\YahooDataProvider(new \GuzzleHttp\Client()),
    new \ForexCalculator\PrecisionProviders\MoneyPrecisionProvider(),
    new \ForexCalculator\PrecisionProviders\RiskRewardRatioPrecisionProvider()
);

# Calculator settings

$symbol = 'eurusd';
$outputCurrency = 'usd';
$extendedPoint = true;

$tradeAttributesCalculator = $tradeAttributesCalculatorFactory->create('eurusd', 'usd', $extendedPoint);

# Factory to create prices to trade

$priceNumberFactory = new \ForexCalculator\DataObjects\FloatNumberFactory(
    new \ForexCalculator\PrecisionProviders\PricePrecisionProvider($symbol, $extendedPoint)
);

$trade = new \ForexCalculator\DataObjects\Trade(
    $priceNumberFactory->create('1.03953'),
    $priceNumberFactory->create('1.03936'),
    $priceNumberFactory->create('1.04016')
);

# Loss and profit for trade and size 20000 units

$loss = $tradeAttributesCalculator->getLoss($trade, 20000);
$profit = $tradeAttributesCalculator->getProfit($trade, 20000);

$riskRewardRatio = $tradeAttributesCalculator->getRiskRewardRatio($trade);
```

### Number of units by maximal risk calculator

[](#number-of-units-by-maximal-risk-calculator)

```
...

$numberOfUnitsCalculator = new \ForexCalculator\Services\NumberOfUnitsByMaximalLossCalculator(
    $symbol,
    $outputCurrency,
    $extendedPoint,
    $tradeAttributesCalculatorFactory
);

$moneyNumberFactory = new \ForexCalculator\DataObjects\FloatNumberFactory(
    new \ForexCalculator\PrecisionProviders\MoneyPrecisionProvider()
);

# Number of units to trade to risk 180 usd per trade

$numberOfUnits = $numberOfUnitsCalculator->getNumberOfUnits($trade, $moneyNumberFactory->create('180'));
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

5

Last Release

3412d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f9ec91d36c19d91d5c9fa074fef303eb35dab202e74eddc57aaf312ebb67fc97?d=identicon)[michalbrauner](/maintainers/michalbrauner)

---

Top Contributors

[![michalbrauner](https://avatars.githubusercontent.com/u/1190316?v=4)](https://github.com/michalbrauner "michalbrauner (43 commits)")

---

Tags

utilscalculatorforexmoney management

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/michalbrauner-forex-calculator/health.svg)

```
[![Health](https://phpackages.com/badges/michalbrauner-forex-calculator/health.svg)](https://phpackages.com/packages/michalbrauner-forex-calculator)
```

###  Alternatives

[danielstjules/stringy

A string manipulation library with multibyte support

2.4k26.0M191](/packages/danielstjules-stringy)[voku/arrayy

Array manipulation library for PHP, called Arrayy!

4875.5M16](/packages/voku-arrayy)[vaimo/composer-patches

Applies a patch from a local or remote file to any package that is part of a given composer project. Patches can be defined both on project and on package level. Optional support for patch versioning, sequencing, custom patch applier configuration and patch command for testing/troubleshooting added patches.

2994.3M16](/packages/vaimo-composer-patches)[voku/stringy

A string manipulation library with multibyte support

1783.8M19](/packages/voku-stringy)[markrogoyski/ipv4-subnet-calculator

Network calculator for subnet mask and other classless (CIDR) network information.

177813.7k6](/packages/markrogoyski-ipv4-subnet-calculator)[statamic/stringy

A string manipulation library with multibyte support, forked from @statamic

234.5M14](/packages/statamic-stringy)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
