Africa's Premier AgTech Intelligence Platform

Farm Smarter.
Grow Further.

Powered by algorithms. Grounded in financial rigour.

Green Sole translates world-class computer science and CFA-grade financial modelling into actionable intelligence — for every farmer, from Del Monte to your corner plot.

Explore the Platform Study Edition II
3
Farmer Segments
2
LeetCode Problems
3
CFA Topics
8
Revision Questions
Platform Reach

Built for every farmer in Africa

Green Sole scales intelligently — the same core AI adapts its outputs to match the complexity, data, and resources of each user type.

🏭
Enterprise Scale
DEL MONTE · KAKUZI · EXPORT FARMS
Multi-farm portfolio analytics, satellite-linked yield monitoring, and WACC-driven capital allocation across hundreds of hectares and supply chains.
Multi-commodity portfolio optimisation
Supply chain route modelling (Dijkstra)
Real-time satellite yield tracking
WACC & IRR capital project analysis
Commodity price hedging signals
🏛️
Government & Ministry
MINISTRY OF AGRICULTURE · COUNTY GOVT · ADB
National food security modelling, regional subsidy allocation optimisation, and policy impact simulation — turning data into legislative decisions.
National crop yield trend analysis
Budget allocation optimisation (Knapsack)
Food security probability models
Subsidy distribution routing
Climate scenario financial modelling
🌱
Small-Scale Farmer
PRIVATE FARMER · COOPERATIVE MEMBER · YOUTH AGRI
Simple, accessible intelligence — which crops to plant, when to sell, and how to calculate profit — delivered in plain language on any device, even via SMS.
Crop selection on limited land & capital
Break-even & profit calculator
Seasonal price & weather alerts
Microfinance loan viability check
SMS & USSD interface support
LeetCode · Problem 1 of 2

0/1 Knapsack — Crop Portfolio Selection

Given limited land and capital, which combination of crops maximises total profit? This is the classic NP-hard 0/1 Knapsack problem — every farmer solves it intuitively, Green Sole solves it optimally.

Dynamic Programming Hard Time: O(n × W) Space: O(n × W)
Problem Setup — Farmer has 50 acres & KES 150,000
CropAcres RequiredCapital (KES)Expected Profit (KES)Profit/Acre
A · Maize2050,00060,0003,000/ac
B · Tomatoes1570,00090,0006,000/ac
C · Beans3040,00050,0001,667/ac
D · Wheat2560,00075,0003,000/ac
Mathematical Formulation Maximise: Σ pᵢ · xᵢ for i ∈ {A, B, C, D}
Subject to: Σ aᵢ · xᵢ ≤ 50 acres (land constraint)
Σ cᵢ · xᵢ ≤ 150,000 KES (capital constraint)
xᵢ ∈ {0, 1} (each crop: plant or don't)

Manual Enumeration — All Feasible Combinations

A only (Maize)
Acres20 ✓
Capital50k ✓
KES 60,000
B only (Tomatoes)
Acres15 ✓
Capital70k ✓
KES 90,000
C only (Beans)
Acres30 ✓
Capital40k ✓
KES 50,000
D only (Wheat)
Acres25 ✓
Capital60k ✓
KES 75,000
A + B
Acres35 ✓
Capital120k ✓
KES 150,000
A + C
Acres50 ✓
Capital90k ✓
KES 110,000
A + D
Acres45 ✓
Capital110k ✓
KES 135,000
B + C
Acres45 ✓
Capital110k ✓
KES 140,000
B + D ⭐ OPTIMAL
Acres40 ✓
Capital130k ✓
KES 165,000
MAXIMUM
C + D
Acres55 ✗
Capital100k
INFEASIBLE
EXCEEDS LAND
A + B + C
Acres65 ✗
INFEASIBLE
EXCEEDS LAND
A + B + D
Capital180k ✗
INFEASIBLE
EXCEEDS CAPITAL
OPTIMAL PORTFOLIO
Tomatoes (B) + Wheat (D)
40 acres used · KES 130,000 capital deployed
MAX PROFIT
165,000
KES
DP Recurrence Relation — How the Algorithm Thinks

We build a table dp[i][w] = max profit using first i crops with weight (land) capacity w.

DP Recurrence dp[i][w] = dp[i-1][w] if wᵢ > w (can't plant crop i)
dp[i][w] = max(dp[i-1][w], pᵢ + dp[i-1][w - wᵢ]) otherwise

Base case: dp[0][w] = 0 for all w (no crops → zero profit)

Why it's powerful: instead of checking 2ⁿ combinations (brute force: 16 for 4 crops, millions for 20+ crops), DP fills the table in O(n × W) — linear in number of crops × land units.

{} JavaScript — 2-Constraint Knapsack Solver
JAVASCRIPT · KNAPSACK
// Crops: [name, acres, capital, profit]
const crops = [
  ['Maize',    20, 50000, 60000],
  ['Tomatoes', 15, 70000, 90000],
  ['Beans',    30, 40000, 50000],
  ['Wheat',    25, 60000, 75000],
];

const maxAcres   = 50;
const maxCapital = 150000;

// 3D DP: dp[i][a][c] = max profit using first i crops,
//         a acres capacity, c capital capacity
function knapsack(crops, maxA, maxC) {
  const n = crops.length;
  // Using simplified capital in thousands for table size
  const cScale = 10000;
  const mC = maxC / cScale;

  let dp = Array.from({length: maxA + 1}, () =>
    new Array(mC + 1).fill(0));

  for (const [name, acres, cap, profit] of crops) {
    const c = cap / cScale;
    // Traverse backwards to maintain 0/1 property
    for (let a = maxA; a >= acres; a--) {
      for (let k = mC; k >= c; k--) {
        dp[a][k] = Math.max(
          dp[a][k],
          profit + dp[a - acres][k - c]
        );
      }
    }
  }
  return dp[maxA][mC]; // → 165,000
}

console.log(knapsack(crops, 50, 150000));
// → 165000 ✅  (Tomatoes + Wheat)
LeetCode · Problem 2 of 2

Sliding Window — Crop Yield Trend Analysis

A 3-season moving average smooths volatility and reveals whether yields are trending up or down — critical for investment timing and planting decisions.

Sliding Window Easy–Medium Time: O(n) Space: O(1)
Input Data — Maize Yield (tonnes/acre) over 8 Seasons
Raw Yield Series yields = [3.2, 2.8, 4.1, 4.8, 3.6, 5.2, 4.9, 5.5]
Window size: k = 3 seasons

Manual Step-by-Step Calculation

Window 1 → Seasons 1–3 MA₁ = (3.2 + 2.8 + 4.1) / 3 = 10.1 / 3 Result: 3.37 t/ac
Window 2 → Seasons 2–4 MA₂ = (2.8 + 4.1 + 4.8) / 3 = 11.7 / 3 Result: 3.90 t/ac   ↑ +0.53
Window 3 → Seasons 3–5 MA₃ = (4.1 + 4.8 + 3.6) / 3 = 12.5 / 3 Result: 4.17 t/ac   ↑ +0.27
Window 4 → Seasons 4–6 MA₄ = (4.8 + 3.6 + 5.2) / 3 = 13.6 / 3 Result: 4.53 t/ac   ↑ +0.36
Window 5 → Seasons 5–7 MA₅ = (3.6 + 5.2 + 4.9) / 3 = 13.7 / 3 Result: 4.57 t/ac   ↑ +0.04
Window 6 → Seasons 6–8 MA₆ = (5.2 + 4.9 + 5.5) / 3 = 15.6 / 3 Result: 5.20 t/ac   ↑ +0.63 ← Peak
Maize Yield vs 3-Season Moving Average · 8 Seasons
Raw Yield 3-Season MA
OVERALL TREND
+54.3%
MA improvement
GREEN SOLE SIGNAL
EXPAND
Uptrend confirmed
PEAK MA
5.20
t/ac · Window 6
{} JavaScript — Sliding Window Moving Average
JAVASCRIPT · SLIDING WINDOW
// O(n) sliding window — no nested loops needed
function movingAverage(yields, k) {
  if (yields.length < k) return [];

  const result = [];
  let windowSum = 0;

  // Prime the first window
  for (let i = 0; i < k; i++) windowSum += yields[i];
  result.push(+(windowSum / k).toFixed(2));

  // Slide: add next, drop first — O(1) per step
  for (let i = k; i < yields.length; i++) {
    windowSum += yields[i] - yields[i - k];
    result.push(+(windowSum / k).toFixed(2));
  }
  return result;
}

const yields = [3.2,2.8,4.1,4.8,3.6,5.2,4.9,5.5];
console.log(movingAverage(yields, 3));
// → [3.37, 3.90, 4.17, 4.53, 4.57, 5.20] ✅
CFA · Financial Analysis 1 of 3

Break-even Analysis — Minimum Viable Harvest

At what output volume does Green Sole's farmer cover all costs? Break-even analysis is the first gate every viable farm must pass — it answers the question before a seed is planted.

CFA Level I Financial Analysis
Cost Structure — Tomato Farm (Optimal Crop from Knapsack)
ItemTypeAmount (KES)Note
Land Lease + EquipmentFixed120,000Per season
Labour (fixed portion)Fixed60,000Per season
Total Fixed Costs (FC)180,000
Seeds, fertiliser, waterVariable15 / unitPer kg tomato
Selling PriceRevenue45 / unitPer kg tomato

Step-by-Step Mathematical Working

Contribution Margin per Unit CM = Selling Price − Variable Cost per Unit CM = KES 45 − KES 15 = KES 30 Each kg sold contributes KES 30 toward covering fixed costs.
Break-even Quantity (Q*) Q* = FC / CM = 180,000 / 30 Q* = 6,000 kg The farm must harvest and sell at least 6,000 kg to avoid a loss.
Break-even Revenue (R*) R* = Q* × Selling Price = 6,000 × 45 R* = KES 270,000 Total revenue at which the farm exactly breaks even.
Margin of Safety (if producing 8,000 kg) MoS = (Actual Output − Q*) / Actual Output × 100 MoS = (8,000 − 6,000) / 8,000 × 100 = 25% A 25% buffer — production can drop 25% before the farm loses money.
Summary of Formulae CM = P − VC = 45 − 15 = 30 KES/unit
Q* = FC / CM = 180,000 / 30 = 6,000 units
R* = Q* × P = 6,000 × 45 = 270,000 KES
MoS = (Q_actual − Q*) / Q_actual × 100
→ At 8,000 kg output: MoS = 25% ✓
Output Volume Zones
Relative sizes illustrate the loss vs profit regions around Q* = 6,000 kg
← LOSS ZONE (Below 6,000 kg)
PROFIT ZONE (Above 6,000 kg) →
0 kgQ* = 6,000 kg8,000 kg
CFA · Financial Analysis 2 of 3

WACC — Weighted Average Cost of Capital

WACC is the minimum return a farm investment must generate to satisfy both its equity investors and debt holders. It is the true hurdle rate — and the heart of CFA capital budgeting.

CFA Level I–II Capital Budgeting
Capital Structure — Green Sole Farm Investment
SourceAmount (KES)WeightCost
Equity (shareholders)300,00060% (Wₑ)Kₑ = 18%
Debt (bank loan)200,00040% (Wd)Kd = 12%
Total Capital (V)500,000

Step 1 — Cost of Equity via CAPM

CAPM Formula Kₑ = Rƒ + β × (Rₘ − Rƒ) = Rƒ + β × ERP Where Rƒ = risk-free rate, β = beta (systematic risk), ERP = equity risk premium.
Input Values Rƒ = 8% (Kenya Gov't Treasury Bill rate) β = 1.25 (Agricultural sector — above market average of 1.0) ERP = 8% (Market return − risk-free rate)
Cost of Equity Result Kₑ = 8% + 1.25 × 8% = 8% + 10% = 18% A β of 1.25 means agriculture moves 25% more than the market — commanding extra return.

Step 2 — After-Tax Cost of Debt

Tax Shield — Why debt is cheaper than it looks After-tax Kd = Kd × (1 − T) Interest payments are tax-deductible, reducing the effective cost of debt.
Calculation After-tax Kd = 12% × (1 − 0.30) = 12% × 0.70 After-tax Kd = 8.4% Tax rate T = 30% (Kenya corporate tax rate).

Step 3 — WACC Calculation

WACC Formula WACC = Wₑ × Kₑ + Wd × Kd × (1 − T)

WACC = 0.60 × 18% + 0.40 × 12% × (1 − 0.30)
WACC = 0.60 × 18% + 0.40 × 8.4%
WACC = 10.80% + 3.36%
WACC = 14.16%
14.16%
WACC
Equity weight (Wₑ)60%
Cost of Equity (Kₑ) via CAPM18.0%
Equity contribution to WACC10.80%
Debt weight (Wd)40%
After-tax Cost of Debt8.40%
Debt contribution to WACC3.36%
WACC (Hurdle Rate) 14.16%
CFA · Financial Analysis 3 of 3

Payback Period & Profitability Index

Two complementary metrics: Payback tells you when you recover your investment. The Profitability Index tells you how much value each shilling deployed generates.

CFA Level I Capital Budgeting
Cash Flow Series (same as Edition I — carries forward)
Inputs CF = [−500,000; 120,000; 150,000; 180,000; 220,000; 260,705]
Year 0 = Initial investment | Years 1–5 = Farm operating cash flows

Payback Period — Cumulative Cash Flow Timeline

Year 0 CF: −500,000 Cumulative: −500,000
Year 1 CF: +120,000 Cumulative: −380,000
Year 2 CF: +150,000 Cumulative: −230,000
Year 3 CF: +180,000 Cumulative: −50,000 ← Almost there
Year 4 CF: +220,000 Cumulative: +170,000 ← Recovered ✓
Exact Payback Period Remaining balance after Year 3 = KES 50,000 Year 4 cash flow = KES 220,000 Payback = 3 + (50,000 / 220,000) = 3 + 0.227 = 3.23 years Investment is recovered in approximately 3 years and 2.7 months.
Payback Period Formula Payback = Last year with negative balance + (|Remaining balance| / Next year CF)
Payback = 3 + (50,000 / 220,000)
Payback = 3.23 years ≈ 3 years, 2.7 months ✓

Profitability Index (PI)

PI Formula PI = PV of Future Cash Flows / |Initial Investment| PI = (NPV + Initial Investment) / Initial Investment PI > 1 means the project creates more value than it costs.
Sum of Present Values (discounted @ 15%) PV = 104,347.83 + 113,422.82 + 118,324.00 + 125,786.57 + 129,617.34 PV = KES 591,498.56
Profitability Index Result PI = 591,498.56 / 500,000 PI = 1.183 Every KES 1 invested generates KES 1.183 in present value — an 18.3% value premium.
1.183
INTERPRETATION GUIDE
PI < 1 Destroys value → REJECT
PI = 1.000 Exactly breaks even → Indifferent
PI = 1.183 ✓ Creates value → ACCEPT
PI >> 1 Exceptional returns → Priority project
Interactive Tool

Live Break-even & WACC Calculator

Adjust any parameter to see how the financial picture changes in real time. Built for every farmer — from small-scale to enterprise.

INPUT YOUR FARM PARAMETERS
CONTRIBUTION MARGIN
BREAK-EVEN QUANTITY (Q*)
BREAK-EVEN REVENUE (R*)
MARGIN OF SAFETY
WACC (HURDLE RATE)
STATUS
Revision · 8 Questions

Test Your Understanding

Questions span both LeetCode and CFA topics covered today. Some require mental calculation — show your working, then check.

QUESTION 01 · KNAPSACK · EASY
Which crop combination was identified as optimal given 50 acres and KES 150,000 capital?
A
Maize only
B
Maize + Tomatoes (A + B)
C
Tomatoes + Wheat (B + D)
D
Beans + Wheat (C + D)
QUESTION 02 · KNAPSACK · MEDIUM
Why must a 0/1 Knapsack DP table be traversed backwards (right to left) when solving it in-place?
A
To improve time complexity
B
To prevent an item from being selected more than once
C
To reduce space complexity
D
To handle negative profits correctly
QUESTION 03 · SLIDING WINDOW · CALCULATE
Given yields = [3.2, 2.8, 4.1, 4.8, 3.6, 5.2, 4.9, 5.5] and k = 3, what is the 3-season moving average for Window 4 (seasons 4–6)?
MA = (y₄ + y₅ + y₆) / k = (4.8 + 3.6 + 5.2) / 3
A
3.90 t/ac
B
4.17 t/ac
C
4.53 t/ac
D
5.20 t/ac
QUESTION 04 · BREAK-EVEN · CALCULATE
If the farmer's fixed costs rise to KES 210,000 (all else equal), what is the new break-even quantity?
Q* = FC / CM = FC / (P − VC) = FC / 30
A
6,000 units
B
7,000 units
C
7,500 units
D
8,000 units
QUESTION 05 · CAPM · INTERPRET
In the CAPM formula Kₑ = Rƒ + β × ERP, what does a beta (β) of 1.25 tell us about the agricultural investment?
A
The investment is less risky than the market
B
The investment moves exactly with the market
C
The investment is 25% more volatile than the market, requiring higher return
D
The investment moves inversely to the market
QUESTION 06 · WACC · CALCULATE
A new farm project is 70% equity (Kₑ = 20%) and 30% debt (Kd = 10%, T = 25%). What is the WACC?
WACC = Wₑ × Kₑ + Wd × Kd × (1 − T)
A
17.0%
B
16.25%
C
15.5%
D
15.0%
QUESTION 07 · PAYBACK PERIOD · ANALYSE
The payback period is calculated as 3.23 years. What is the key limitation of this metric that a CFA analyst must flag?
A
It is too difficult to calculate
B
It ignores the time value of money
C
It overestimates total profitability
D
It can have multiple solutions
QUESTION 08 · PROFITABILITY INDEX · APPLY
Two mutually exclusive projects: Project A has PI = 1.35, Project B has PI = 1.18 but NPV = KES 400,000 vs Project A's NPV = KES 80,000. Which should a rational investor choose?
A
Project A — because PI is higher
B
Project B — because NPV is far higher
C
Either — PI and NPV always agree
D
Neither — both metrics are flawed
—/8

Push to GitHub — Keep Learning Everywhere

Add this file to your Green Sole repo and enable GitHub Pages to access it on any device — your iPad, phone, or a friend's laptop.

git add green_sole_platform.html
git commit -m "Add Green Sole Platform Edition II"
git push origin main
Then visit: https://YOUR_USERNAME.github.io/green-sole-case-study/