1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// financial_ratios - rust library (crate)
// GNU licensed, license file can be found at the root of the repository
// Copyright 2016 - Mohamed Hayibor

pub fn current_ratio(current_assets: f64, current_liabilities: f64) -> f64 {
    current_assets / current_liabilities
}

#[test]
fn test_current_ratio() {
    let test = current_ratio(5000., 2000.);
    assert_eq!(test, 2.5);
}

pub fn quick_ratio(current_assets: f64, inventories: f64, current_liabilities: f64) -> f64 {
    (current_assets - inventories) / current_liabilities
}

#[test]
fn test_quick_ratio() {
    let test = quick_ratio(5000., 1000., 2000.);
    assert_eq!(test, 2.);
}

pub fn cash_ratio(cash: f64, current_liabilities: f64) -> f64 {
    cash / current_liabilities
}

#[test]
fn test_cash_ratio() {
    let test = cash_ratio(1000., 500.);
    assert_eq!(test, 2.);
}

pub fn debt_ratio(total_liabilities: f64, total_assets: f64) -> f64 {
    total_liabilities / total_assets
}

#[test]
fn test_debt_ratio() {
    let test = debt_ratio(1000., 5000.);
    assert_eq!(test, 0.2);
}

pub fn times_interest_earned(ebit: f64, interest_expense: f64) -> f64 {
    ebit / interest_expense
}

#[test]
fn test_times_interest_earned() {
   let test = times_interest_earned(3000., 500.);
   assert_eq!(test, 6.);
}

pub fn cash_coverage_ratio(ebit: f64, depreciation: f64, interest_expense: f64) -> f64 {
    (ebit + depreciation) / interest_expense
}

#[test]
fn test_cash_coverage() {
    let test = cash_coverage_ratio(3000., 2000., 500.);
    assert_eq!(test, 10.);
}

pub fn inventory_turnover(cogs: f64, inventory: f64) -> f64 {
    cogs / inventory
}

#[test]
fn test_inventory_turnover() {
    let test = inventory_turnover(2000., 4000.);
    assert_eq!(test, 0.5);
}

pub fn receivables_turnover(sales: f64, accounts_receivable: f64) -> f64 {
    sales / accounts_receivable
}

#[test]
fn test_receivables_turnover() {
    let test = receivables_turnover(4000., 1000.);
    assert_eq!(test, 4.);
}

pub fn total_asset_turnover(sales: f64, total_assets: f64) -> f64 {
    sales / total_assets
}

#[test]
fn test_total_asset_turnover() {
    let test = total_asset_turnover(4000., 2000.);
    assert_eq!(test, 2.);
}

pub fn profit_margin(net_income: f64, sales: f64) -> f64 {
    net_income / sales
}

#[test]
fn test_profit_margin() {
    let test = profit_margin(2000., 4000.);
    assert_eq!(test, 0.5);
}

pub fn return_on_assets(net_income: f64, total_assets: f64) -> f64 {
    net_income / total_assets
}

#[test]
fn test_return_on_assets() {
   let test = return_on_assets(2000., 5000.);
   assert_eq!(test, 0.4);
}

pub fn return_on_equity(net_income: f64, total_owners_equity: f64) -> f64 {
    net_income / total_owners_equity
}

#[test]
fn test_return_on_equity() {
    let test = return_on_equity(2000., 5000.);
    assert_eq!(test, 0.4);
}

pub fn earnings_per_share(net_income: f64, outstanding_shares: f64) -> f64 {
    net_income / outstanding_shares
}

#[test]
fn test_eps() {
   let test = earnings_per_share(5000., 500000.);
   assert_eq!(test, 0.01);
}